package com.zengshuai.miniprogrambackend.Controller;

import com.zengshuai.miniprogrambackend.Entity.Order;
import com.zengshuai.miniprogrambackend.Mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderMapper orderMapper;


    @GetMapping("/getorderlistbystatus/{status}")
    public List<Order> getorderlistbystatus(@PathVariable("status") int status) {
        orderMapper.getOrderlistbystatus(status);

        return orderMapper.getOrderlistbystatus(status);
    }

    @GetMapping("/getorderlistbystatusAndemployeeid/{status}/{employeeid}")
    public List<Order> getorderlistbystatusAndemployeeid(@PathVariable("status") int status,@PathVariable("employeeid") int employeeid) {
        orderMapper.getorderlistbystatusAndemployeeid(status,employeeid);
        System.out.println(status);

        System.out.println(employeeid);
        System.out.println("ssssssssssssssssss");
        System.out.println(orderMapper.getorderlistbystatusAndemployeeid(status,employeeid));

        return orderMapper.getorderlistbystatusAndemployeeid(status,employeeid);
    }

    @GetMapping("/getAllOrderlist")
    public List<Order> getAllorderlist() {


        return orderMapper.getAllOrderlist();
    }


    //用户提交订单
    @GetMapping("/submitorder")
    public void submitOrder(String booktime, String serviceid, String price, String servicename, String address, String openid, String telnumber) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
        String orderid = simpleDateFormat.format(new Date());

        LocalDateTime dateTime = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String ordertime = dateTime.format(formatter);

//        System.out.println(openid);
        orderMapper.saveOrder(booktime, serviceid, price, servicename, address, openid, telnumber, orderid,ordertime);

    }

    @GetMapping("/updateStatusTo5/{id}")
    public void updateStatusTo5(@PathVariable("id") int id) {

        orderMapper.updateStatusTo5(id);

    }


    //设置订单状态已完成 4
    @GetMapping("/updateStatusTo4/{orderid}")

    public void updateStatusTo4(@PathVariable("orderid") int id) {


        orderMapper.updateStatusTo4(id);

    }

    //重新下单 status：1
    @GetMapping("/updateStatusTo1/{id}")
    public void updateStatusTo1(@PathVariable("id") int id) {

        orderMapper.updateStatusTo1(id);

    }

    //用户删除订单
    @GetMapping("/deleteorder/{id}")
    public void deleteorder(@PathVariable("id") int id) {

        orderMapper.deleteorder(id);

    }


    //员工接单 set status=2
    @GetMapping("/receiveorder")
    public void receiveorder(int id, String employeeid) {

        orderMapper.updateStatusTo2(id);
        orderMapper.receiveorder(id, employeeid);

    }


    //员工已上门 status=6
    @GetMapping("/updateStatusTo6/{id}")
    public void updateStatusTo6(@PathVariable("id") int id) {

        orderMapper.updateStatusTo6(id);

    }


    //员工完成收款 status=3
    @GetMapping("/updateStatusTo3/{id}")
    public void updateStatusTo3(@PathVariable("id") int id) {

        orderMapper.updateStatusTo3(id);

    }


}
